#ifndef __INPUT_SOURCE_MANAGER__
#define __INPUT_SOURCE_MANAGER__

#include <memory>
#include <future>
#include <sqlite_orm/sqlite_orm.h>
#include <mutex>
#include <condition_variable>
#include "Util/util.h"
#include "jsoncpp/json.h"
#include "Network/Buffer.h"

using namespace Fdt;
using namespace sqlite_orm;

const std::string InputSourceDbPath = "/mnt/mtd/input_source.db";

struct InputSource{
    int m_id;
    std::string m_source_type;   //NETWORK
    std::string m_source_ability;  //   video/audio/video_audio
    std::string m_source_content;  
    std::string m_source_desc;
};


class InputSourceManager{
public:
    using Ptr = std::shared_ptr<InputSourceManager>;
    static Ptr instance();
    InputSourceManager(const std::string& sourceDbName = InputSourceDbPath);
    ~InputSourceManager();

    void RegistRPC();
    bool Add(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);
    bool Delete(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);
    bool Set(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);
    bool Get(const Json::Value &request, const Fdt::BufferMap::Ptr &inMap, Json::Value &response, Fdt::BufferMap::Ptr &outMap);

private:
    using StorageType = decltype(make_table("input_source",
                            make_column("id", &InputSource::m_id, primary_key()),
                            make_column("type", &InputSource::m_source_type),
                            make_column("ability", &InputSource::m_source_ability),
                            make_column("content", &InputSource::m_source_content),
                            make_column("desc", &InputSource::m_source_desc) ));
    std::shared_ptr<internal::storage_t<StorageType>> m_storager_ptr;
    std::string m_db_path;
};

#endif